.PHONY: all

ifeq (${P_BASE},)
all:
	@echo "ERROR: the variable [P_BASE] is not set"
else

include ${P_BASE}/global/utils/make/target
include ${P_BASE}/global/utils/make/cmds
include ${P_BASE}/global/utils/make/escape

T_CC_LIBCOMMON_FLAGS  ?= ${T_CC_GLOBAL_FLAGS} -gstabs ${T_CC_FLAG_INC}${P_BASE} -nostdlib -nostdinc -fno-builtin
T_LIBGCC		      ?= $(shell $(call T_CC,,"",-print-libgcc-file-name))

SRCFILES:= $(shell $(call C_FIND,.,-iname "*.c") | $(call C_SED,-e 's!\./!!g'))
OBJFILES:= $(addprefix ${T_BASE}/libcommon_,\
		     $(addsuffix .o,$(foreach FILE,${SRCFILES},$(call E_ENCODE,${FILE}))))
DEPFILES:= $(OBJFILES:.o=.d)

all: ${OBJFILES}

-include ${DEPFILES}

${T_BASE}/libcommon_%.d:
	@$(call C_ECHO,DEP $(call E_DECODE,$*))
	${V}$(call T_CC, $(call E_DECODE,$*),$@,-MM $(T_CC_LIBCOMMON_FLAGS) -MT $(@:.d=.o))

${T_BASE}/libcommon_%.o: ${T_BASE}/libcommon_%.d
	@$(call C_ECHO,CC $(call E_DECODE,$*))
	${V}$(call T_CC,$(call E_DECODE,$*),$@,${T_CC_LIBCOMMON_FLAGS} ${T_CC_FLAG_OBJ})

endif
